#define _MSVC_
#include "MyMysqlPool.h"

void th(void* p)
{
	MyMysqlPool* pInstance = (MyMysqlPool*)p;


	while (1)
	{
		MyMysql* pMyMysql = pInstance->GetConnection();
		if (pMyMysql == NULL)
		{
			Sleep(1000);
			continue;
		}
		pMyMysql->Query("select * from user", strlen("select * from user"));
		while (pMyMysql->Next())
		{
			std::cout << (*pMyMysql)["id"].toInt() << " " << (*pMyMysql)["account"].toString() << " " << (*pMyMysql)["password"].toString() << std::endl;
		}
		pInstance->ReleaseConnection(pMyMysql);
	}

}

int main()
{
	//
	//MyMysql m;
	//m.Connect("127.0.0.1", "root", "123456", "sun", 3306);
	//m.Query("select * from user", strlen("select * from user"));

	//while (m.Next())
	//{
	//	std::cout << m["id"].toInt() << " " << m["account"].toString() << " " << m["password"].toString() << std::endl;
	//}

	MyMysqlPool* pInstance = MyMysqlPool::getInstance();
	pInstance->SetConnectionInfo("127.0.0.1", "root", "123456", "sun", 3306);
	pInstance->SetMax(3);
	pInstance->Load();

	std::thread t1(th, pInstance);
	std::thread t2(th, pInstance);
	std::thread t3(th, pInstance);
	std::thread t4(th, pInstance);
	std::thread t5(th, pInstance);


	t1.join();
	t2.join();
	t3.join();
	t4.join();
	t5.join();


	return 0;
}